<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div id="app">
        <!-- 组件的使用 -->
        <button-counter1></button-counter1>
        <button-counter2></button-counter2>
    </div>
    <script src="../js/vue.min.js"></script>
    <script>
        // 事件中心
        var eventHub = new Vue();
        // 组件1定义
        Vue.component('button-counter1', {
            data: function() {
                return {
                    count: 0
                }
            },
            template: `
            <div>
            <div>TOM:{{count}}</div>
            <div>
            <button @click='handle1'>点击</button>    
            </div>    
            </div>
            `,
            methods: {
                handle1: function() {
                    this.count++
                }
            },
            mouted: function() {
                eventHub.$on('tom-event', (val) => {
                    this.count++
                })
            }
        });
        // 组件2定义
        Vue.component('button-counter2', {
            data: function() {
                return {
                    res: 0
                }
            },
            template: `
            <div>
            <div>Jerry:{{res}}</div>
            <div>
            <button @click='handle2'>点击</button>    
            </div>    
            </div>
            `,
            methods: {
                handle2: function() {
                    this.res++
                }
            },
            mouted: function() {
                eventHub.$on('jerry-event', (val) => {
                    this.res++
                })
            }
        });
        let vm = new Vue({
            el: "#app",
            data: {

            }
        })
    </script>
</body>

</html>